feat(#442484): suppress TaskCanceledException APM noise during pod graceful shutdown#113
Merged
Merged
Conversation
…aceful shutdown Add guard clause to ReceiverWrapper.OnExceptionOccured: when the exception is an OperationCanceledException with IsCancellationRequested=true, log at Debug and return early instead of logging at Error. This eliminates ~250 spurious APM error entries per day caused by all concurrent receivers being cancelled simultaneously during pod graceful shutdown via CloseAsync. Real transport errors (non-cancelled token) continue to be logged at Error, preserving the original behaviour for genuine failures. Also initialise _onExceptionReceivedHandler to a no-op default (non-nullable) so OnExceptionOccured is safe to call without RegisterMessageHandler, which enables direct unit testing via a TestableReceiverWrapper subclass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
e4a4b5c to
c0a43b9
Compare
benspeth
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a guard clause to
ReceiverWrapper.OnExceptionOccuredthat detectsOperationCanceledException/TaskCanceledExceptionraised during pod graceful shutdown and logs them atDebuginstead ofError.Root cause: When a pod shuts down,
CloseAsynccancels all concurrent receive loops simultaneously. Each loop raises anOperationCanceledExceptionwithIsCancellationRequested == trueand callsProcessErrorAsync, which previously logged every one atErrorlevel — producing ~250 spurious APM error entries per day in ExternalCommEmailing.Fix: In
OnExceptionOccured, checkexceptionEvent.Exception is OperationCanceledException oce && oce.CancellationToken.IsCancellationRequested. If true → log atDebugand return early. Real transport errors (non-cancelled token) continue to log atError.Changes
src/Ev.ServiceBus/Management/Wrappers/ReceiverWrapper.cs— guard clause + initialise_onExceptionReceivedHandlerto non-nullable no-op defaulttests/Ev.ServiceBus.UnitTests/ReceiverWrapperTests.cs— 2 new unit tests covering both pathsdocs/CHANGELOG.md— 5.7.2 entryTest plan
OnExceptionOccured_WithCancelledToken_DoesNotLogError— verifies noLogErrorcall whenIsCancellationRequested == trueOnExceptionOccured_WithNonCancelledToken_LogsError— verifiesLogErroris still called for genuine transport errors